{  Statement: http://acmp.ru/?main=task&id_task=118
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n,k,ans:longint;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n,k);
ans := 0;
for i := 2 to n do
    ans := (ans + k) mod i;
write(ans + 1);
end.
